package com.sein.foods;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;

public class SaveData extends Activity implements OnClickListener {

	private SQLHandler dh;
	static final int DIALOG_ID = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.save);
		View add = findViewById(R.id.Button01add);
		add.setOnClickListener(this);
		View home = findViewById(R.id.Button01home);
		home.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.Button01home:
			Intent i = new Intent(this, SeinFoods.class);
			startActivity(i);
			break;
		case R.id.Button01add:
			View editText1 = (EditText) findViewById(R.id.name);
			View editText2 = (EditText) findViewById(R.id.number);
			View editText3 = (EditText) findViewById(R.id.skypeId);
			View editText4 = (EditText) findViewById(R.id.address);
			String myEditText1 = ((TextView) editText1).getText().toString();
			String myEditText2 = ((TextView) editText2).getText().toString();
			String myEditText3 = ((TextView) editText3).getText().toString();
			String myEditText4 = ((TextView) editText4).getText().toString();
			this.dh = new SQLHandler(this);
			this.dh.insert(SQLHandler.INSERT,  new String[]{myEditText1, myEditText2, myEditText3, myEditText4});
			showDialog(DIALOG_ID);
			break;
		}

	}

	protected final Dialog onCreateDialog(final int id) {
		Dialog dialog = null;
		switch (id) {
		case DIALOG_ID:
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage(
					"Information saved successfully ! Add Another Info?")
					.setCancelable(false)
					.setPositiveButton("No",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface dialog,
										int which) {
									// TODO Auto-generated method stub
									dialog.cancel();
								}
							});
			AlertDialog alert = builder.create();
			dialog = alert;
			break;

		default:
		}
		return dialog;

	}

}
